package com.meixun.xuanke.course.service.impl;

import com.meixun.xuanke.course.service.RedisService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class RedisServiceImpl implements RedisService {

    @Resource
    private RedisTemplate<String, Object> redisTemplate;
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Override
    public void removeCinfig(String schoolId) {
        Set<String> key = redisTemplate.keys("getConfig_" + schoolId+"_*");
        redisTemplate.delete(key);
        key = redisTemplate.keys("queryCourseDescribeStr*");
        redisTemplate.delete(key);
    }

    @Override
    public void removeCourseInfo(String schoolId, String courseId) {

        //更新科目分类
        redisTemplate.delete("querySubType_"+schoolId);
        //更新课程列表
        redisTemplate.delete("queryCourseListBySchool_"+schoolId);

        if(courseId!=null){
            //更新选课详情
            redisTemplate.delete("queryCourseById_"+courseId);
        }
    }

    @Override
    public void removeStudentCourseInfo(String courseId) {
        //操作用户了

        //更新数量
        redisTemplate.delete("queryCoursSize_"+courseId);

        //更新自己的选课列表
        Set<String> key = redisTemplate.keys("queryMyCourseListByStu*");
        redisTemplate.delete(key);

        //更新学习的选课列表
        key = redisTemplate.keys("queryCourseListByStu_*");
        redisTemplate.delete(key);


    }

    @Override
    public void removeCourseTime(String schoolId) {
        //更新列表
        redisTemplate.delete("queryCourseListBySchool_"+schoolId);
    }
}
